package com.tuyrt.demo.singleton


/**
 * author: Administrator on 2021/11/10.
 * desc:
 */
class Singleton3 {
    companion object {
        val instance: Singleton3 by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
            Singleton3()
        }
    }
}

class SingletonParams private constructor(val p1: Int) {
    companion object {
        @Volatile
        private var instance: SingletonParams? = null

        fun get(p1: Int) =
            instance ?: synchronized(this) {
                instance ?: SingletonParams(p1).also { instance = it }
            }
    }
}